package com.vivebest.utils.kd.config;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * <p>
 * </p>
 *
 * @author zsk
 * @date 2020/8/16 上午11:04
 */
@Configuration
public class K8sExecutorConfig {

    @Bean
    public ExecutorService executorService() {
        //获取系统处理器个数，作为线程池数量
        int nThreads = Runtime.getRuntime().availableProcessors();
        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
                .setNameFormat("k8s-pool-%d").build();

        return new ThreadPoolExecutor(5, 21,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(160), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());

    }
}
